package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.usian.pojo.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class consumer {


    @KafkaListener(topics = {"topic2"})
    public void receiverMessage(ConsumerRecord<?,?> record){

        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);

        if(optional.isPresent()){
            Object msg = record.value();
            User user = JSON.parseObject((String)msg,User.class);
            System.out.println("message=="+user);
        }

    }
}
